package cn.minhx.mw.acr.sdk;

import com.zhipu.oapi.ClientV4;
import com.zhipu.oapi.Constants;
import com.zhipu.oapi.service.v4.model.*;

import java.util.ArrayList;
import java.util.List;

public class Reviewer {
    public String review(String diffCode) {
        ClientV4 client = new ClientV4.Builder("597a2b82c5f34b2bbace6bb0ed2d552c.07t5nI4ydQEBaqBL").build();
        List<ChatMessage> messages = new ArrayList<>() {{
            add(new ChatMessage(ChatMessageRole.USER.value(), "你是一个高级编程架构师，精通各类场景方案、架构设计和编程语言请，请您根据git diff记录，对代码做出评审。代码如下:"));
            add(new ChatMessage(ChatMessageRole.USER.value(), diffCode));
        }};
        ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest.builder()
                .model(Constants.ModelChatGLM4Flash)
                .stream(Boolean.FALSE)
                .invokeMethod(Constants.invokeMethod)
                .messages(messages)
                .build();
        ModelApiResponse invokeModelApiResp = client.invokeModelApi(chatCompletionRequest);
        StringBuilder sb = new StringBuilder();
        for (Choice choice : invokeModelApiResp.getData().getChoices()) {
            sb.append(choice.getMessage().getContent());
        }
        return sb.toString();
    }

}
